package com.fsoft.core.utils;

import java.util.Collection;
import java.util.Map;
import java.util.UUID;

import org.apache.commons.lang.StringUtils;

/**
 * F-Soft 是否为空工具类判断
 * @package com.fsoft.core.utils
 * @author Fish
 * @email it.fish2010@foxmail.com
 * @date 2020-02-18
 * @CopyRight © F-Soft
 **/
@SuppressWarnings(value = { "rawtypes" })
public class OgnlUtils {
	/**
	 * 可以用于判断 Map,Collection,String,Array,Long是否为空
	 * 
	 * @param o java.lang.Object.
	 * @return boolean.
	 */
	public static boolean isEmpty(Object o) {
		if (o == null)
			return true;
		if (o instanceof String && StringUtils.isBlank((String) o)) {
			return true;
		} else if (o instanceof Collection && ((Collection) o).isEmpty()) {
			return true;
		} else if (o.getClass().isArray() && ((Object[]) o).length == 0) {
			return true;
		} else if (o instanceof Map && ((Map) o).isEmpty()) {
			return true;
		} else if (o instanceof StringBuilder && ((StringBuilder) o).length() == 0)
			return true;
		return false;
	}

	/**
	 * 可以用于判断 Map,Collection,String,Array是否不为空
	 * 
	 * @param c
	 * @return
	 */
	public static boolean isNotEmpty(Object o) {
		return !isEmpty(o);
	}

	/**
	 * 返回一个大写的随机字符串
	 * @user Fish
	 * @date 2019-05-06
	 * @return
	 */
	public static final String randomUpperCaseId() {
		return randomLowerCaseId().toUpperCase();
	}

	/***
	 * 返回小写的随机ID
	 * @user Fish
	 * @date 2019-05-06
	 * @return
	 */
	public static final String randomLowerCaseId() {
		return UUID.randomUUID().toString().replaceAll("-", "");
	}

	/**
	 * F-Soft 获取文件名的扩展名
	 * @author it_software(it.fish2010@foxmail.com)
	 * @date 2020-02-28
	 * @param fileName
	 * @return
	 */
	public static String getFileNameExt(String fileName) {
		return fileName.substring(fileName.lastIndexOf('.') + 1);
	}
}
